const {merge} = require('webpack-merge')
const baseConfig = require('./webpack.common.js')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const path = require("path")

module.exports = merge(baseConfig, {
  mode: 'production',
  // devtool: 'none',
  module: {
    rules: [
      {
        //css文件处理
        test: /\.css?$/,
        //执行顺序从右到左
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(js|vue)$/,
        use: "eslint-loader",
        enforce: "pre",
      },
      {
        test: /\.less?$/,
        use: ["vue-style-loader", "css-loader", "less-loader"],
      },
      {
        test: /\.vue$/,
        use: "vue-loader",
      },
      {
        test: /\.js$/,
        exclude: /node_modules/, 
        use: {
          loader: "babel-loader",
          options: {
            presets: [["@babel/preset-env", { targets: "defaults" }]],
            plugins: ["@babel/plugin-proposal-class-properties"],
          },
        },
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        use: {
          loader: "url-loader",
          options: {
            limit: 10 * 1024,
            esModule: false,
          },
        },
      }
     
    ],
  },

  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin({
      filename: 'main.css'
    }),
    // 复制公共部分
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.join(__dirname,'public/'),
          to: path.join('public'),
        }
      ]
    }
     
    )
  ]
})